package com.lvcoding.secdemo1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @description 描述
 * @date 2022-02-06 下午10:26
 * @author wuyanshen
 */
@Controller
public class TestController {

	@RequestMapping("index")
	public String index(Model model) {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		User user = (User) authentication.getPrincipal();

		model.addAttribute("username", user.getUsername());
		model.addAttribute("authorities", user.getAuthorities());
		model.addAttribute("name", "小红");
		return "index";
	}

}
